import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xinxuan/http/http_util_service.dart';
import 'package:xinxuan/vo/common_vo/common_pagination_vo.dart';
import 'package:xinxuan/vo/seckill_my_commodity_list_vo.dart';

class MyCommodityPageController extends GetxController {

  int page = 1;
  var seckillMyCommodityListVo = SeckillMyCommodityListVo(data: [], meta: SeckillMyCommodityListMeta(pagination: CommonPagination(total: 0))).obs;

  final ScrollController scrollController = ScrollController();

  @override
  void onReady() {
    getMyCommodityList();
    super.onReady();
  }



  /// 获取我的商品
  getMyCommodityList({bool loading = true}) async {
    page = 1;
    SeckillMyCommodityListVo temp = await HttpUtilService.getMyCommodityList(page: page, loading: loading);
    seckillMyCommodityListVo.value = temp;
    update();
  }

  /// 加载更多我的商品列表
  onloadMyCommodityList() async {
    if (seckillMyCommodityListVo.value.meta!.pagination!.total! <= seckillMyCommodityListVo.value.data!.length) {
      return;
    }
    page++;
    SeckillMyCommodityListVo temp = await HttpUtilService.getMyCommodityList(page: page, loading: false);
    seckillMyCommodityListVo.value.data!.addAll(temp.data!);
    update();
  }

}